From 315cd5394e67b12829bd2a1edb283eef81366148 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Thu, 13 Jun 2019 00:51:38 +0200 Subject: [PATCH] lib: fix clippy Look, the type is fine. It's only an opaque thing to ensure lifetimes anyway. --- .../rust/src/repo_checkout_at_options.rs | 13 ++++------ .../repo_checkout_filter.rs | 24 +++---------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/rust-bindings/rust/src/repo_checkout_at_options.rs b/rust-bindings/rust/src/repo_checkout_at_options.rs index 0ebf7be7..4b49e2c6 100644 --- a/rust-bindings/rust/src/repo_checkout_at_options.rs +++ b/rust-bindings/rust/src/repo_checkout_at_options.rs @@ -1,7 +1,7 @@ use crate::{RepoCheckoutMode, RepoCheckoutOverwriteMode, RepoDevInoCache, SePolicy}; -use glib::translate::{Stash, ToGlib, ToGlibPtr}; +use glib::translate::*; use libc::c_char; -use ostree_sys::{OstreeRepoCheckoutAtOptions, OstreeRepoDevInoCache, OstreeSePolicy}; +use ostree_sys::*; use std::path::PathBuf; mod repo_checkout_filter; @@ -50,6 +50,7 @@ type StringStash<'a, T> = Stash<'a, *const c_char, Option>; type WrapperStash<'a, GlibT, WrappedT> = Stash<'a, *mut GlibT, Option>; impl<'a> ToGlibPtr<'a, *const OstreeRepoCheckoutAtOptions> for RepoCheckoutAtOptions { + #[allow(clippy::type_complexity)] type Storage = ( Box, StringStash<'a, PathBuf>, @@ -90,7 +91,7 @@ impl<'a> ToGlibPtr<'a, *const OstreeRepoCheckoutAtOptions> for RepoCheckoutAtOpt if let Some(filter) = &self.filter { options.filter_user_data = filter.to_glib_none().0; - options.filter = repo_checkout_filter::trampoline(); + options.filter = Some(repo_checkout_filter::filter_trampoline); } Stash( @@ -112,10 +113,6 @@ mod tests { use crate::RepoCheckoutFilterResult; use gio::{File, NONE_CANCELLABLE}; use glib_sys::{GFALSE, GTRUE}; - use ostree_sys::{ - OSTREE_REPO_CHECKOUT_MODE_NONE, OSTREE_REPO_CHECKOUT_MODE_USER, - OSTREE_REPO_CHECKOUT_OVERWRITE_NONE, OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL, - }; use std::ffi::{CStr, CString}; use std::ptr; @@ -190,7 +187,7 @@ mod tests { ); assert_eq!((*ptr).unused_ints, [0; 6]); assert_eq!((*ptr).unused_ptrs, [ptr::null_mut(); 3]); - assert_eq!((*ptr).filter, repo_checkout_filter::trampoline()); + assert!((*ptr).filter == Some(repo_checkout_filter::filter_trampoline)); assert_eq!( (*ptr).filter_user_data, options.filter.as_ref().unwrap().to_glib_none().0, diff --git a/rust-bindings/rust/src/repo_checkout_at_options/repo_checkout_filter.rs b/rust-bindings/rust/src/repo_checkout_at_options/repo_checkout_filter.rs index f83af232..44a3a7f3 100644 --- a/rust-bindings/rust/src/repo_checkout_at_options/repo_checkout_filter.rs +++ b/rust-bindings/rust/src/repo_checkout_at_options/repo_checkout_filter.rs @@ -1,10 +1,8 @@ use crate::{Repo, RepoCheckoutFilterResult}; -use glib::translate::{ - from_glib_borrow, from_glib_none, FromGlibPtrNone, Stash, ToGlib, ToGlibPtr, -}; +use glib::translate::*; use glib_sys::gpointer; use libc::c_char; -use ostree_sys::{OstreeRepo, OstreeRepoCheckoutFilterResult}; +use ostree_sys::*; use std::path::{Path, PathBuf}; /// A filter callback to decide which files to checkout from a [Repo](struct.Repo.html). The @@ -64,7 +62,7 @@ impl FromGlibPtrNone for &RepoCheckoutFilter { /// /// # Panics /// If any parameter is a null pointer, the function panics. -unsafe extern "C" fn filter_trampoline( +pub(super) unsafe extern "C" fn filter_trampoline( repo: *mut OstreeRepo, path: *const c_char, stat: *mut libc::stat, @@ -87,25 +85,9 @@ unsafe extern "C" fn filter_trampoline( result.to_glib() } -/// Returns the trampoline function in a `Some`. -/// -/// This is mostly convenient because the full type needs to be written out in fewer places. -pub(super) fn trampoline() -> Option< - unsafe extern "C" fn( - *mut OstreeRepo, - *const c_char, - *mut libc::stat, - gpointer, - ) -> OstreeRepoCheckoutFilterResult, -> { - Some(filter_trampoline) -} - #[cfg(test)] mod tests { use super::*; - use glib::translate::ToGlibPtr; - use ostree_sys::OSTREE_REPO_CHECKOUT_FILTER_SKIP; use std::ffi::CString; use std::ptr; -- 2.30.2